#include "head.h"
#include <stdio.h>

void do_command(int socket_fd,int sig,char* now_path){

    if(sig == CD){
        do_comm_cd(socket_fd,now_path);
    }else if(sig == LS){
        do_comm_ls(socket_fd);
    }else if(sig == PWD){
        
    }


    return;

}

void do_comm_cd(int socket_fd,char* now_path){

    printf("start command cd\n");
    int path_len;
    recv(socket_fd,&path_len,sizeof(int),MSG_WAITALL);
    recv(socket_fd,now_path,path_len,MSG_WAITALL);
    printf("now_path : %s\n",now_path);

    return;
}

void do_comm_ls(int socket_fd){

    printf("start do_command_ls\n");
    int count = 0;
    while(1){

        int name_len = 0;
        recv(socket_fd,&name_len,sizeof(int),MSG_WAITALL);
        if(name_len == 99){
            break;
        }
        char name[60] = {0};
        recv(socket_fd,name,name_len,MSG_WAITALL);
        printf("%-16s",name);
        fflush(stdout);
        count++;
        if(count%6 == 0){
            printf("\n");
        }

    }
    printf("\n");
    return;

}












